package com.qf.emp.service.impl;

import com.qf.emp.dao.ProfileDao;
import com.qf.emp.dao.impl.ProfileDaoImpl;
import com.qf.emp.entity.Page;
import com.qf.emp.entity.Profile;
import com.qf.emp.service.ProfileService;
import com.qf.emp.utils.DbUtils;

import java.util.List;

public class ProfileServiceImpl implements ProfileService {
    ProfileDao profileDao = new ProfileDaoImpl();
    @Override
    public Profile showPer(int id) {
        Profile per = null;
        try {
            DbUtils.begin();
            per = profileDao.selectPer(id);
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }
        return per;
    }

    @Override
    public int updatePer(Profile per) {
        int result = 0;
        try {
            DbUtils.begin();
            result = profileDao.update(per);
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<Profile> showAll(Page page) {
        List<Profile> pers = null;
        try {
            DbUtils.begin();
            //获取总行数
            long count = profileDao.selectCount();
            page.setTotalCounts((int) count);
            //根据controller传递的page对象查询对应数据
            pers = profileDao.selectAll(page);
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }
        return pers;
    }



}
